
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;

public class XMLwriter {

    public static void main(String[] args) throws Exception {
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter writer = factory.createXMLStreamWriter(System.out);

        writer.writeStartDocument("test");
        writer.writeStartDocument("2.0");
        writer.setDefaultNamespace("google.com");
        writer.writeEntityRef("news");
        writer.writeStartElement("information");
        writer.writeStartElement("W");
        writer.writeAttribute("type", "thkfjsldkf");
        writer.writeCharacters("hi hi");
        writer.writeEndElement();
        writer.writeStartElement("W");
        writer.writeAttribute("type", "thkfjsldkf");
        writer.writeCharacters("hi hi");
        writer.writeEndElement();
        writer.writeStartElement("W");
        writer.writeAttribute("type", "thkfjsldkf");
        writer.writeCharacters("hi hi");
        writer.writeEndElement();
        writer.writeStartElement("W");
        writer.writeAttribute("type", "thkfjsldkf");
        writer.writeCharacters("hi hi");
        writer.writeEndElement();
        writer.writeStartElement("W");
        writer.writeAttribute("type", "thkfjsldkf");
        writer.writeCharacters("hi hi");
        writer.writeEndElement();
        writer.writeStartElement("W");
        writer.writeAttribute("type", "thkfjsldkf");
        writer.writeCharacters("hi hi");
        writer.writeEndElement();
        writer.writeStartElement("W");
        writer.writeAttribute("type", "thkfjsldkf");
        writer.writeCharacters("hi hi");
        writer.writeEndElement();
        writer.writeEmptyElement("what");
        writer.setPrefix("pre1", "pre2");
        writer.writeEntityRef("tin tuc buoi sang");
        writer.writeComment("this is the comment");
        writer.writeCharacters("một con vịt xòe ra hai cái cánh & một cái cánh được một đĩa thịt vịt");
        writer.writeDTD("\n\t\bkkk");
        writer.writeStartDocument("utf-8", "1.0");
        writer.writeEndElement();
        writer.writeEndDocument();

        writer.flush();
        writer.close();

    }
}
